#include "thread_memory_pool.hpp"

namespace mina
{
	void * ThreadMemoryPool::allocate()
	{
		_lock.lock();

		while (empty())
		{
			_cond.wait(_lock);
		}

		void * addr = MemoryPool::allocate();

		_lock.unlock();

		return addr;
	}

	void ThreadMemoryPool::deallocate(void * addr)
	{
		_lock.lock();

		bool bempty = empty();
		MemoryPool::deallocate(addr);

		if (bempty)
		{
			_cond.signal();
		}
		_lock.unlock();
	}
}

